﻿<!DOCTYPE html>
<html lang="en">
<head>
    <title id='Description'>In this sample is illustrated the jqxTreeGrid Data Paging API</title>
    <meta name="description" content="Data Paging API - JavaScript Tree Grid Demo | jQWidgets">     
    <link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" type="text/css" />
    <script type="text/javascript" src="../../scripts/jquery-1.11.1.min.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxcore.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxdata.js"></script> 
    <script type="text/javascript" src="../../jqwidgets/jqxbuttons.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxscrollbar.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxlistbox.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxdropdownlist.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxdatatable.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxtreegrid.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxpanel.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxradiobutton.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxinput.js"></script>
    <script type="text/javascript" src="../sampledata/generatedata.js"></script>
    <script type="text/javascript" src="../../scripts/demos.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            // prepare the data
            var source =
            {
                dataType: "array",
                dataFields: [
                    { name: "name", type: "string" },
                    { name: "quantity", type: "number" },
                    { name: "id", type: "number" },
                    { name: "parentid", type: "number" },
                    { name: "price", type: "number" },
                    { name: "date", type: "date" },
                    { name: "customer", type: "string" }
                ],
                hierarchy:
                {
                    keyDataField: { name: 'id' },
                    parentDataField: { name: 'parentid' }
                },
                id: 'id',
                localData: generateordersdata()
            };
            var dataAdapter = new $.jqx.dataAdapter(source);
            // create Tree Grid
            $("#treeGrid").jqxTreeGrid(
            {
                width: 560,
                source: dataAdapter,
                sortable: true,
                pageable: true,
                autoRowHeight: false,
                pagerPosition: "both",
                pagerMode: 'advanced',
                ready: function () {
                    $("#treeGrid").jqxTreeGrid('expandRow', '2');
                },
                columns: [
                  { text: 'Order Name', dataField: "name", align: 'center', width: 250 },
                  { text: 'Customer', dataField: "customer", align: 'center', width: 250 },
                  { text: 'Price', dataField: "price", cellsFormat: "c2", align: 'center', cellsAlign: 'right', width: 80 },
                  {
                      text: 'Order Date', dataField: "date", align: 'center', cellsFormat: "dd-MMMM-yyyy hh:mm", cellsRenderer: function (rowKey, column, cellValue, rowData, cellText) {
                          if (rowData.level === 0) {
                              return dataAdapter.formatDate(cellValue, "dd-MMMM-yyyy");
                          }
                          return cellText;
                      }
                  }
                ]
            });

            // Settings
            $("#pagerModeDropDownList").jqxDropDownList({ height: 25,  width: 120, selectedIndex: 1, source: ["default", "advanced"], autoDropDownHeight: true });
            $("#pagerModeDropDownList").on('select', function (event) {
                if (event.args.index == 0) {
                    $("#treeGrid").jqxTreeGrid({ pagerMode: "default" });
                }
                else {
                    $("#treeGrid").jqxTreeGrid({ pagerMode: "advanced" });
                }
            });
            $("#pagerPositionDropDownList").jqxDropDownList({ height: 25,  width: 120, selectedIndex: 2, source: ["top", "bottom", "both"], autoDropDownHeight: true });
            $("#pagerPositionDropDownList").on('select', function (event) {
                if (event.args.index == 0) {
                    $("#treeGrid").jqxTreeGrid({ pagerPosition: "top" });
                }
                else if (event.args.index == 1) {
                    $("#treeGrid").jqxTreeGrid({ pagerPosition: "bottom" });
                }
                else {
                    $("#treeGrid").jqxTreeGrid({ pagerPosition: "both" });
                }
            });

            $('#events').jqxPanel({ width: 150, height: 150});

            $("#gotopage").jqxInput({ height: 25, width: 120 });
            $("#applyPage").jqxButton({ height: 25});
            $("#applyPage").click(function () {
                var page = parseInt($("#gotopage").val());
                if (!isNaN(page)) {
                    page--;
                    if (page < 0) page = 0;
                    $("#treeGrid").jqxTreeGrid('goToPage', page);
                }
            });

            // raised when a page is changed.
            $("#treeGrid").on("pageChanged", function (event) {
                $("#eventslog").css('display', 'block');
                if ($("#events").find('.logged').length >= 5) {
                    $("#events").jqxPanel('clearcontent');
                }

                var args = event.args;
                var eventData = "<div>Page:" + (1+args.pagenum) + ", Page Size: " + args.pagesize + "</div>";
                $('#events').jqxPanel('prepend', '<div class="logged" style="margin-top: 5px;">' + eventData + '</div>');
            });

            // raised when the size of a page is changed.
            $("#treeGrid").on("pageSizeChanged", function (event) {
                $("#eventslog").css('display', 'block');
                $("#events").jqxPanel('clearcontent');

                var args = event.args;
                var eventData = "<div>Page:" + (1+args.pagenum) + ", Page Size: " + args.pagesize + ", Old Page Size: " + args.oldpagesize + "</div>";
                $('#events').jqxPanel('prepend', '<div style="margin-top: 5px;">' + eventData + '</div>');
            });
        });
    </script>
</head>
<body class='default'>
    <div style="float: left;" id="treeGrid">
    </div>
    <div style="font-size: 13px; font-family: verdana; float: left; margin-left: 30px;">
        <div><strong>Settings</strong></div>
        <div style="margin-top: 10px;">
            <div>Pager Mode:</div>
            <div id="pagerModeDropDownList" style="margin-top: 5px;"></div>
            <div  style="margin-top: 10px;">Pager Position:</div>
            <div id="pagerPositionDropDownList" style="margin-top: 5px;"></div>
            <div  style="margin-top: 10px;">Go to Page:</div>
            <input id="gotopage" value="1" style="margin-top: 5px;"/>
            <button id="applyPage">Apply</button>
        </div>
        <div style="margin-top: 10px;">
            <div>Event Log:</div>
            <div id="events" style="margin-top: 5px;"></div>
        </div>    
    </div>
</body>
</html>
